package util;

import java.util.ArrayList;

@SuppressWarnings("all")
//分页工具类
public class PageHelper {
    private Integer dateCount;  //查询数据的总条数
    private final Integer showNumber = 5; //每页显示的条数，改为5条更合理
    private Integer pageCount;  //参与分页的总页数
    private Integer pageIndex = 1;  //当前是第几页
    private ArrayList listIndex;    //当前页显示项的集合

    // 新增：起始索引，用于SQL查询
    private Integer startIndex;

    public Integer getDateCount() {
        return dateCount;
    }

    //传入数据总条数的同时计算好页面页数
    public void setDateCount(Integer dateCount) {
        this.dateCount = dateCount;
        pageCount = getPageCount();
    }

    public Integer getShowNumber() {
        return showNumber;
    }

    public Integer getPageCount() {
        if (dateCount == null || dateCount == 0) {
            return 0;
        }
        pageCount = this.dateCount % this.showNumber == 0 ?
                this.dateCount / this.showNumber :
                this.dateCount / this.showNumber + 1;
        return pageCount;
    }

    public Integer getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(Integer pageIndex) {
        this.pageIndex = pageIndex;
        // 计算起始索引
        if (pageIndex != null && pageIndex > 0) {
            this.startIndex = (pageIndex - 1) * showNumber;
        }
    }

    public ArrayList getListIndex() {
        return listIndex;
    }

    public void setListIndex(ArrayList listIndex) {
        this.listIndex = listIndex;
    }

    // 新增：获取起始索引
    public Integer getStartIndex() {
        return startIndex;
    }

    // 新增：设置起始索引
    public void setStartIndex(Integer startIndex) {
        this.startIndex = startIndex;
    }
}